package com.example.demo.entity;

import org.bson.types.Binary;
import org.bson.types.ObjectId;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;

import java.util.Date;
import java.util.Objects;

/**
 * File 文档类.
 * 
 * @since 1.0.0 2017年3月28日
 * @author <a href="https://waylau.com">Way Lau</a> 
 */
@Document
public class MongoDbFile {
	@Id  // 主键
	private String id;
    private String name; // 文件名称
    private String contentType; // 文件类型
    private long size;
    private Date uploadDate;
    private String md5;
    private Binary content; // 文件内容
    private String path; // 文件路径
    private String filesId; // 文件路径

    public String getPath() {
		return path;
	}

	public void setPath(String path) {
		this.path = path;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getContentType() {
		return contentType;
	}

	public void setContentType(String contentType) {
		this.contentType = contentType;
	}

	public long getSize() {
		return size;
	}

	public void setSize(long size) {
		this.size = size;
	}

	public Date getUploadDate() {
		return uploadDate;
	}

	public void setUploadDate(Date uploadDate) {
		this.uploadDate = uploadDate;
	}

	public String getMd5() {
		return md5;
	}

	public void setMd5(String md5) {
		this.md5 = md5;
	}

	public Binary getContent() {
		return content;
	}

	public void setContent(Binary content) {
		this.content = content;
	}

    protected MongoDbFile() {
    }

    public MongoDbFile(String name, String contentType, long size, Binary content) {
    	this.name = name;
    	this.contentType = contentType;
    	this.size = size;
    	this.uploadDate = new Date();
    	this.content = content;
    }

	public String getFilesId() {
		return filesId;
	}

	public void setFilesId(String filesId) {
		this.filesId = filesId;
	}

	@Override
	public String toString() {
		return "MongoDbFile{" +
				"id='" + id + '\'' +
				", name='" + name + '\'' +
				", contentType='" + contentType + '\'' +
				", size=" + size +
				", uploadDate=" + uploadDate +
				", md5='" + md5 + '\'' +
				", content=" + content +
				", path='" + path + '\'' +
				", filesId='" + filesId + '\'' +
				'}';
	}

	@Override
	public boolean equals(Object o) {
		if (this == o) return true;
		if (o == null || getClass() != o.getClass()) return false;
		MongoDbFile that = (MongoDbFile) o;
		return size == that.size &&
				Objects.equals(id, that.id) &&
				Objects.equals(name, that.name) &&
				Objects.equals(contentType, that.contentType) &&
				Objects.equals(uploadDate, that.uploadDate) &&
				Objects.equals(md5, that.md5) &&
				Objects.equals(content, that.content) &&
				Objects.equals(path, that.path) &&
				Objects.equals(filesId, that.filesId);
	}

	@Override
	public int hashCode() {

		return Objects.hash(id, name, contentType, size, uploadDate, md5, content, path, filesId);
	}

}
